package com.xhd.exception;

import com.xhd.pool.Resource;
import com.xhd.server.ServerConfig;

public abstract class XException extends Exception {
	private int ExceptID;
	  private int LanguageID;
	  private String Message;
	  private int ExceptionType;
	  private String[] ExceptionsStr = new String[3];
	  private String InsideMsg;
	//  private Throwable excThrowable = null;
	  private Throwable excThrowable= null;
	 public XException()
	  {
		 
	  }
	

	  public XException(int paramInt)
	  {
	    this.ExceptID = paramInt;
	    getMessages();
	  }

	  public XException(int paramInt, String paramString)
	  {
	    super(paramString);
	    this.ExceptID = paramInt;
	    this.ExceptionsStr[0] = paramString;
	    getMessages();
	  }

	  public XException(int paramInt, String paramString1, String paramString2)
	  {
	    super(paramString1);
	    this.ExceptID = paramInt;
	    this.ExceptionsStr[0] = paramString1;
	    this.ExceptionsStr[1] = paramString2;
	    getMessages();
	  }

	  public XException(int paramInt, String paramString1, String paramString2, String paramString3)
	  {
	    super(paramString1);
	    this.ExceptID = paramInt;
	    this.ExceptionsStr[0] = paramString1;
	    this.ExceptionsStr[1] = paramString2;
	    this.ExceptionsStr[2] = paramString3;
	    getMessages();
	  }

	  public XException(String paramString)
	  {
	    super(paramString);
	    this.ExceptionsStr[0] = paramString;
	    this.ExceptID = 40001;
	    getMessages();
	  }

	  public XException(int paramInt, String[] paramArrayOfString)
	  {
	    this.ExceptID = paramInt;
	    if ((paramArrayOfString != null) && (paramArrayOfString.length > 0))
	      this.ExceptionsStr = paramArrayOfString;
	    getMessages();
	  }

	  public int getId()
	  {
	    return this.ExceptID;
	  }

	  public String getInsideMsg()
	  {
	    return this.InsideMsg;
	  }
	  
	  private void getMessages()
	  {
	    this.Message = getMessage(this.LanguageID);
	  }
	  
	  public String getMessage(int paramInt)
	  {
	    String str = null;
	    String[] arrayOfString = (String[])null;
	    int i = 0;
	    if (this.ExceptionsStr != null)
	    {
	      i = 1;
	      arrayOfString = new String[this.ExceptionsStr.length];
	      for (int j = 0; j < this.ExceptionsStr.length; ++j)
	        if ((this.ExceptionsStr[j] != null) && (this.ExceptionsStr[j].length() > 0))
	          arrayOfString[j] = "\"" + this.ExceptionsStr[j] + "\"";
	        else
	          arrayOfString[j] = "";
	    }
	    if (this.ExceptID == 0)
	      this.ExceptID = 99999;
	    Object localObject;
	    if (ServerConfig.resourcePool != null)
	    {
	      localObject = ServerConfig.resourcePool.getErrorMessage(this.ExceptID);
	      if (localObject == null)
	      {
	        this.ExceptionType = 1;
	        str = (i != 0) ? arrayOfString[0] : ServerConfig.resourcePool.getString(paramInt, 20);
	      }
	      else
	      {
	        str = ((Resource)localObject).getText(paramInt, arrayOfString);
	        if ((str == null) || (str.length() < 1))
	          str = ServerConfig.resourcePool.getString(paramInt, 21);
	      }
	    }
	    else if ((arrayOfString != null) && (arrayOfString.length > 0))
	    {
	      localObject = new StringBuffer(128);
	      int k = arrayOfString.length;
	      for (int l = 0; l < k; ++l)
	      {
	        if (arrayOfString[l] == null)
	          continue;
	        if (arrayOfString[l].length() < 1)
	          continue;
	        ((StringBuffer)localObject).append(arrayOfString[l]);
	        if (1 + l >= k)
	          continue;
	        ((StringBuffer)localObject).append("\r\n");
	      }
	      str = ((StringBuffer)localObject).toString();
	    }
	    else
	    {
	      str = "";
	    }
	    return ((String)str + "(" + this.ExceptID + ")");
	  }

	  public XException(XException paramSinocpcException)
	  {
	    this.ExceptID = paramSinocpcException.ExceptID;
	    this.LanguageID = paramSinocpcException.LanguageID;
	    this.Message = paramSinocpcException.Message;
	    this.ExceptionType = paramSinocpcException.ExceptionType;
	    this.ExceptionsStr = paramSinocpcException.ExceptionsStr;
	    this.InsideMsg = paramSinocpcException.InsideMsg;
	    this.excThrowable = paramSinocpcException.excThrowable;
	  }
	  
	  public int getType()
	  {
	    return this.ExceptionType;
	  }

	

	  public void setInsideMsg(String paramString)
	  {
	    this.InsideMsg = paramString;
	  }

	  public void setLanguage(int paramInt)
	  {
	    if (this.LanguageID == paramInt)
	      return;
	    this.LanguageID = paramInt;
	     getMessages();
	  }

	  public void setThrowable(Throwable paramThrowable)
	  {
	    this.excThrowable = paramThrowable;
	  }

	  public Throwable getThrowable()
	  {
	    return this.excThrowable;
	  }
}
